<template>
  <el-card class="order-item" shadow="hover">
    <div class="order-header">
      <div class="order-info">
        <span class="order-number">订单号：{{ order.orderNo }}</span>
        <span class="order-time">{{ order.createTime }}</span>
      </div>
      <el-tag :type="statusType" effect="dark" size="small">
        {{ order.statusText }}
      </el-tag>
    </div>
    <div class="order-content">
      <div class="product-info">
        <img
          :src="order.productImage"
          :alt="order.productName"
          class="product-image"
        />
        <div class="product-details">
          <h3>{{ order.productName }}</h3>
          <p class="product-desc">{{ order.description }}</p>
          <div class="price-info">
            <span class="price">￥{{ order.price }}</span>
            <span class="quantity">x{{ order.quantity }}</span>
          </div>
        </div>
      </div>
      <div class="order-total">
        <div class="total-amount">
          总计：<span>￥{{ order.price * order.quantity }}</span>
        </div>
      </div>
    </div>
    <div class="order-footer">
      <div class="order-actions">
        <!-- 待付款状态 -->
        <template v-if="order.status === 'pending'">
          <el-button
            type="primary"
            size="small"
            class="primary-btn"
          >
            立即支付
          </el-button>
          <el-button type="text" size="small" class="text-btn">
            取消订单
          </el-button>
        </template>
        
        <!-- 已完成状态 -->
        <template v-else-if="order.status === 'completed'">
          <el-popover
            placement="top"
            width="180"
            trigger="hover"
            popper-class="service-popover"
          >
            <div class="qr-container">
              <img :src="serviceQRCode" alt="客服二维码" class="qr-image">
              <p class="qr-tip">扫码联系客服申请售后</p>
            </div>
            <el-button slot="reference" type="text" size="small" class="text-btn">
              申请售后
            </el-button>
          </el-popover>
          
          <el-button type="text" size="small" class="text-btn">
            再次购买
          </el-button>
        </template>
        
        <!-- 已取消状态 -->
        <template v-else-if="order.status === 'cancelled'">
          <el-button type="text" size="small" class="text-btn">
            删除订单
          </el-button>
          <el-button type="primary" size="small" class="primary-btn">
            再次购买
          </el-button>
        </template>
        
        <!-- 其他状态 -->
        <template v-else>
          <el-button type="text" size="small" class="text-btn">
            查看详情
          </el-button>
        </template>
      </div>
    </div>
  </el-card>
</template>

<script>
export default {
  name: "OrderItem",
  props: {
    order: {
      type: Object,
      required: true
    }
  },
  data() {
    return {
      serviceQRCode: require('@/assets/info/service-qr.png')
    }
  },
  computed: {
    statusType() {
      const types = {
        pending: "warning",
        completed: "success",
        cancelled: "info",
        processing: "primary",
        shipped: "success"
      };
      return types[this.order.status] || "info";
    }
  }
};
</script>

<style scoped>
.order-item {
  margin-bottom: 20px;
  border-radius: 12px;
  transition: all 0.3s ease;
}

.order-item:hover {
  transform: translateY(-3px);
}

.order-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.order-info {
  display: flex;
  gap: 20px;
  color: #666;
}

.order-number {
  font-weight: bold;
}

.order-content {
  border-top: 1px solid #eee;
  border-bottom: 1px solid #eee;
  padding: 20px 0;
}

.product-info {
  display: flex;
  gap: 20px;
}

.product-image {
  width: 80px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
}

.product-details {
  flex: 1;
}

.product-details h3 {
  color: #3f5d62;
  margin: 0 0 10px 0;
}

.product-desc {
  color: #666;
  margin-bottom: 10px;
}

.price-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.price {
  color: #f56c6c;
  font-weight: bold;
}

.quantity {
  color: #999;
}

.order-total {
  text-align: right;
  margin-top: 15px;
}

.total-amount {
  font-size: 1.1rem;
  color: #666;
}

.total-amount span {
  color: #f56c6c;
  font-weight: bold;
  margin-left: 5px;
}

.order-footer {
  margin-top: 20px;
  display: flex;
  justify-content: flex-end;
}

.order-actions {
  display: flex;
  gap: 10px;
}

.primary-btn {
  background: #3f5d62;
  border-color: #3f5d62;
}

.primary-btn:hover, .primary-btn:focus {
  background: #4a6e74;
  border-color: #4a6e74;
}

.text-btn {
  color: #3f5d62;
}

/* 修改二维码样式 */
.qr-container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.qr-image {
  width: 120px;
  height: 120px;
  margin-bottom: 10px;
}

.qr-tip {
  margin: 0;
  font-size: 12px;
  color: #666;
  line-height: 1.4;
}

@media (max-width: 768px) {
  .product-info {
    flex-direction: column;
  }

  .product-image {
    width: 100%;
    height: 200px;
  }

  .order-info {
    flex-direction: column;
    gap: 5px;
  }

  .order-actions {
    flex-wrap: wrap;
  }
}
</style>

<style>
/* 全局样式，确保弹出框样式正确 */
.service-popover {
  padding: 15px !important;
  border-radius: 8px !important;
}
</style> 